package com.tliaswebmanagement.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class TimeAspect {
    @Around("execution(* com.tliaswebmanagement.service.impl.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pip) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pip.proceed();
        long end = System.currentTimeMillis();
        log.info("{}:方法的执行耗时是:{} ms", pip.getSignature().getName(), end - start);

        return result;
    }

    @Before("execution(* com.tliaswebmanagement.service.*.*(..))")
    public void before() {
        log.info("前置通知");
    }

    @After("execution(* com.tliaswebmanagement.service.*.*(..))")
    public void after() {
        log.info("最终通知");
    }
    @AfterReturning("execution(* com.tliaswebmanagement.service.*.*(..))")
    public void afterReturning() {
        log.info("后置通知");
    }
}
